<template>
  <div class="editForm-wrapper">
    <!--车辆信用分编辑dialog-->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="editVisible"
    >
      <el-form
        label-width="83px"
        :rules="dataRule"
        ref="editForm"
        :model="editForm"
      >
        <el-form-item label="车牌号:" prop="truckId">
          <el-select clearable v-model="editForm.truckId">
            <el-option
              label="---请选择---"
              :value="0"></el-option>
            <el-option
              v-for="item in dictOptions"
              :key="item.id"
              :label="item.truckNumber"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="信用类型:" prop="ruleType">
          <el-select clearable v-model="editForm.ruleType">
            <el-option
              label="---请选择---"
              :value="0"></el-option>
            <el-option
              v-for="item in  $dictUtils.getDictList('scoreRuleType')"
              :key="item.value"
              :label="item.label"
              :value="Number(item.value)">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="信用分值:" prop="score">
          <el-input v-model="editForm.score" v-thousands.score="editForm" ></el-input>
        </el-form-item>
        <el-form-item label="描述:" prop="remark">
          <el-input v-model="editForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <div class="footer-input">
          <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick
            >确定</el-button
          >
          <el-button size="small" @click="close()">取消</el-button>
        </div>

      </span>
    </el-dialog>
  </div>
</template>
<script>
import { edit,getTruckList } from '@/api/truck/creditScore/creditScore.js'
export default {
  components: {},
  data () {
    return {
      method: '',
      title: '',
      editForm: {
        truckId: '',
        ruleType: 0,
        sourceId: '',
        score: '',
        state: 0,
        remark: '',
        id: ''
      },
      page: {
        pageSize: 10,
        pageNo: 1,
        total: 0
      },
      dictOptions: [],
      editVisible: false,
      dataRule: {
        truckId: [
          { required: true, message: '请选择车牌号', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
	handleClose(done) {
		this.$Msg.confirm({
			title:'您确定要关闭吗？',
			content:this.GLOBAL.FORM_CLOSE_TIPS,
			confirmCall:()=>{
				done();
			}
		})
	},
    init (method, editForm) {
      if (method === 'add') {
        this.editVisible = true
        this.$nextTick(() => {
          this.$refs.editForm.resetFields()
          this.editForm = {}
        })
        this.editForm.id = ''
        this.title = '新增信用记录'
      } else if (method === 'edit') {
        this.$http({
          url: `/truck/truckCreditScore/queryById?id=${editForm.id}`,
          method: 'get'
        }).then(({data}) => {
          if (data.success) {
            this.editVisible = true
            this.editForm =  data.result
          } else {
            this.editVisible = false
          }
        })
        this.title = '修改信用记录'
      }
    },
    close () {
      this.editForm = {}
      this.editVisible = false
    },
    getList (params, props, orderName, orderByAORC) {
      this.loading = true
      getTruckList({
        pageSize: params.pageSize,
        pageNo: params.pageNo,
        props: props,
        orderBy: orderName,
        orderByAORC: orderByAORC
      }).then(({data}) => {
        if (data.code === '200') {
          this.dictOptions = data.result
        }
      })
    },
    doSubmit () {
      this.$refs['editForm'].validate((valid) => {
        if (valid) {
          this.$set(this.editForm, 'props', 1)
          edit(this.editForm).then(({data}) => {
            if (data.code === '200') {
              this.$message({
                message: '编辑成功',
                type: 'success'
              })
              this.editVisible = false
              this.$emit('refreshDataList')
            }
          })
        }
      })
    }
  },
  mounted () {
    this.getList(this.page, 1, '', 'asc')
  }
}
</script>
<style lang="scss" scoped>
  // ::v-deep .el-form-item:last-child{
  //   margin-bottom: 0 !important;
  // }
// .editForm-wrapper{
//     ::v-deep.el-dialog{
//       .el-input__inner{
//         width: 320px;
//       }
//     }
//   }
.view-container {
  margin-bottom: 20px;
  display: flex;
  .label-container {
    width: 150px;
    text-align: right;
    font-size: 16px;
    font-weight: 400;
    color: #666666;
  }
  .form-container {
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    width: 200px;
  }
}
</style>
